import { Alert, Breadcrumb, Button, Card, Modal, Popover, Space, Tabs, Typography } from "antd";
import Search from "@/components/Search";
import Sheet from "@/components/Sheet";
import dayjs from "dayjs";
import { useState, useMemo, useEffect } from "react";
import { useNavigate } from "react-router-dom";
// import UploadCom from "@/components/UploadCom";
import BtnTool from "@/components/BtnTool";
import { useDispatch } from "react-redux";
import { setShowBtnTool } from "@/store/modules/style";
import Person from "@/components/Person";
import State from "@/components/State";
import { SettingOutlined } from "@ant-design/icons";
import Setable from "@/components/Setable";
import WordShow from "@/components/WordShow";
import { businessriskAPI,risksearchAPI } from '@/apis'

const jyfxTabs = [
    {
        key: 'jyfx_gscg',
        label: '公示催告',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '票号',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '票据类型',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '申请人',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '票面金额',
                dataIndex: 'C5',
                key: 'C5',
                align: 'center',
                render: (dom, rowData, index) => {
                    return rowData.C5?rowData.C5.toLocaleString():rowData.C5
                }
            },
            {
                title: '公告日期',
                dataIndex: 'C6',
                key: 'C6',
            },
        ]
    },
    {
        key: 'jyfx_gqcz',
        label: '股权出质',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '股权出质设立登记日期',
                dataIndex: 'C1',
                key: 'C1'
            },
            {
                title: '登记编号',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '出质人',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '质权人',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '处置股权数额',
                dataIndex: 'C5',
                key: 'C5'
            },
            {
                title: '状态',
                dataIndex: 'C6',
                key: 'C6'
            }
        ]
    },
    {
        key: 'jyfx_dwdb',
        label: '对外担保',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '公告日期',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '担保方',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '被担保方',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '担保方式',
                dataIndex: 'C5',
                key: 'C5'
            },
            {
                title: '担保金额',
                dataIndex: 'C6',
                key: 'C6'
            }
        ]
    },
    {
        key: 'jyfx_sxxx',
        label: '失信信息',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '法定代表人',
                dataIndex: 'C1',
                key: 'C1',
                align: "center"
            },
            {
                title: '执行法院',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '生效法律文书确定的义务',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '失信被执行人行为具体情形',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '案号',
                dataIndex: 'C5',
                key: 'C5',
            },
            {
                title: '涉案金额',
                dataIndex: 'C6',
                key: 'C6'
            },
            {
                title: '被执行人的履行情况',
                dataIndex: 'C7',
                key: 'C7'
            },
            {
                title: '做出执行依据单位',
                dataIndex: 'C8',
                key: 'C8'
            }
        ]
    },
    {
        key: 'jyfx_gqzy',
        label: '股权质押',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '质押冻结类型',
                dataIndex: 'C1',
                key: 'C1',
            },
            {
                title: '质押/冻结起始日',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '质押/冻结截止日',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '实际解除日期',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '实施质押冻结机构',
                dataIndex: 'C5',
                key: 'C5'
            },
            {
                title: '涉及金额',
                dataIndex: 'C6',
                key: 'C6'
            },
            {
                title: '质押/冻结股数',
                dataIndex: 'C7',
                key: 'C7'
            },
            {
                title: '剩余未解押数',
                dataIndex: 'C8',
                key: 'C8'
            },
            {
                title: '累计质押股数',
                dataIndex: 'C9',
                key: 'C9'
            },
            {
                title: '质押/冻结期限描述',
                dataIndex: 'C10',
                key: 'C10'
            },
            {
                title: '备注',
                dataIndex: 'C11',
                key: 'C11'
            },
            {
                title: '质押/冻结事由',
                dataIndex: 'C12',
                key: 'C12'
            }
        ]
    },
    {
        key: 'jyfx_dcdy',
        label: '动产抵押',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '登记日期',
                dataIndex: 'C1',
                key: 'C1'
            },
            {
                title: '登记编号',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '登记机关',
                dataIndex: 'C3',
                key: 'C3',
            },
            {
                title: '被担保债权类型',
                dataIndex: 'C4',
                key: 'C4',
            },
            {
                title: '被担保债权数额',
                dataIndex: 'C5',
                key: 'C5'
            },
            {
                title: '债务期限',
                dataIndex: 'C6',
                key: 'C6'
            },
            {
                title: '担保范围',
                dataIndex: 'C7',
                key: 'C7'
            },
            {
                title: '状态',
                dataIndex: 'C8',
                key: 'C8'
            }
        ]
    },
    {
        key: 'jyfx_jyyc',
        label: '经营异常',
        columns: [
            {
                title: '公司名称',
                dataIndex: 'GSMC',
                key: 'GSMC',
            },
            {
                title: '列入经营异常做出决定机关',
                dataIndex: 'C1',
                key: 'C1',
            },
            {
                title: '列入日期',
                dataIndex: 'C2',
                key: 'C2',
            },
            {
                title: '移出经营异常名录原因',
                dataIndex: 'C3',
                key: 'C3'
            },
            {
                title: '移出日期',
                dataIndex: 'C4',
                key: 'C4'
            },
            {
                title: '移出经营异常作出决定机关',
                dataIndex: 'C5',
                key: 'C5'
            },
            {
                title: '列入经营异常名录原因',
                dataIndex: 'C11',
                key: 'C11'
            }
        ]
    }
]

export default function Jingyingfengxian() {

    // 状态参数
    const [activeKey, setActiveKey] = useState('jyfx_gscg');
    const currentTab = useMemo(() => {
        return jyfxTabs.find(tab => tab.key === activeKey);
    }, [activeKey]);
    const tabColumns = currentTab?.columns || [];
    const [page, setPage] = useState({ pageNum: 1, pageSize: 10 })
    const [selectedRowKeys, setSelectedRowKeys] = useState([]);
    const dispatch = useDispatch()
    const [jyfxSource, setjyfxSource] = useState({ total: 0, data: [] })
    useEffect(() => {
        const currentTab = jyfxTabs.find(tab => tab.key === activeKey);
        setjyfxSource({ total: 0, data: null })
        function getfxdata() {
            businessriskAPI({
                pagenum: page.pageNum,
                pagesize: page.pageSize,
                risktype: currentTab?.label
            }).then(res => {
                setjyfxSource({ total: res.data.total, data: res.data.data })
            })
        }
        getfxdata()
    }, [activeKey,page])
    // 分页
    const handlePage = (pageNum, pageSize) => {
        setPage({
            pageNum,
            pageSize
        })
    }
    // 表格选择
    const handleSelChange = (selectedRowKeys, selectedRows) => {
        setSelectedRowKeys(selectedRowKeys)
        dispatch(setShowBtnTool(selectedRowKeys.length > 0))
    }
    const rowSelection = {
        selectedRowKeys,
        onChange: handleSelChange,
    };
    // 搜索
    const handleSearch = (val) => {
        const currentTab = jyfxTabs.find(tab => tab.key === activeKey);
        risksearchAPI({
            pagenum: page.pageNum,
            pagesize: page.pageSize,
            riskType: currentTab?.label,
            companyName: val.keyword
        }).then(res => {
            setjyfxSource({ total: res.data.total, data: res.data.data })
        })
    }
    return (
        <div>
            <Tabs type="card" activeKey={activeKey} items={jyfxTabs} onChange={(key) => setActiveKey(key)}  />
            <Space direction="vertical" size={16} style={{ width: "100%" }}>
                <Search onSearch={handleSearch}></Search>
                <Card className="table-container">
                    <div className="tableHeader">
                        <h3>明细表</h3>
                    </div>
                    <Sheet columns={tabColumns} dataSource={jyfxSource} rowKey='key' page={page} onChange={handlePage}></Sheet>
                </Card>
            </Space>
        </div>
    )

}